<?php

namespace app\common\model\xiservice;

use think\Model;
use think\Db;


class Schedule extends Model
{

    

    

    // 表名
    protected $name = 'xiservice_worker_schedule';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    public function orderSchedule($worker_id,$order_id,$reserve_time,$duration_time)
    {
        $count = $duration_time/30; 
        //时间分段
        $time_arr = [];
        array_push($time_arr,$reserve_time);
        if($count>1){
            for ($i=0; $i < $count ; $i++) { 
                 $time = $reserve_time + 30*60*($i+1);
                array_push($time_arr,$time);
            }
        }else{
            array_push($time_arr,$reserve_time+30*60);
        }
        for($i=0;$i<count($time_arr);$i++)
        {
            $sdata['user_id'] = $worker_id;
            $sdata['type'] = 2;
            $sdata['order_id'] = $order_id;
            $sdata['date'] =  date('Y-m-d',$time_arr[$i]);
            $sdata['rest_start_time'] =  date('H:i:s',$time_arr[$i]);
            $sdata['rest_timestamp'] =  $time_arr[$i];
            $req =$this->insertGetId($sdata);
        }
    }
    







}
